#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

 struct ListNode 
{
     int val;
    struct ListNode* next;
};

struct ListNode* getIntersectionNode(struct ListNode* head)
{
    struct ListNode* fast = head;
    struct ListNode* slow = head;
    while (fast && fast->next)
    {
        fast = fast->next->next;
        slow = slow->next;
        if (slow == fast)
            return fast;

    }
    return NULL;
}
struct ListNode* detectCycle(struct ListNode* head)
{

    struct ListNode* meet = getIntersectionNode(head);
    if (meet == NULL)
        return NULL;
    while (meet != head)
    {
        meet = meet->next;
        head = head->next;
    }
    return meet;
}